;; EX-44 - BandPass Example from Pd, by Miller Puckette.

;; In this example we use two cascaded bandpass filters to troll for
;; partials in Jonathan Harvey's famous bell sample.

;; Note that filters can give unexpected level changes. The bp~ object
;; (BPR) is designed to have roughly unit gain at the pass band, so
;; the higher you set "Q" the more amplitude is lost. You can correct
;; for this by pushing the output amplitude, but be sure to remember
;; to reset the output amplitude before you reduce Q again. I set the
;; Q to 100 and the output amplitude to 110 or 120 (with the room gain
;; way down.) Then holding the shift key, slowly drag the center pitch
;; upward listening for modes.

;; You can hear partials around 48, 51.3, 55 (faint!), 57 (fainter!),
;; 60, two beating partials around 65, 67, 69, 70.9, 71.75, 72.6, 74,
;; 74.65, 75.6, 77, 81.2, 84.6, 86.5, and probably many more. There's
;; also one down at 36, but it's easier to see it on the meter than
;; hear it.

;; Allocate sound file buffer.

(-> "/b_allocRead" 0 "/n/ext/cvs/pure-data/pd/doc/sound/bell.aiff" 0 -1)

;; Setup <ctl>s and interface.

(begin (ctl-setup! (c 14) "note" (make-spec 36 92 'linear))
       (ctl-setup! (c 15) "bw" (make-spec 1 100 'exponential))
       (controller-interface 1 2 14))

;; Play file in continuous loop through two cascaded band pass filters..

(let* ((freq (MIDICPS (In.kr 14)))
       (bw (In.kr 15))
       (rq (FDiv bw freq)))
  (Pan2.ar (BPF.ar (BPF.ar (PlayBuf.ar 1 0 1 1 0 1) freq rq) freq rq) 0 1))


